#ifndef SLICEFRACTIONCACHE_H
#define SLICEFRACTIONCACHE_H

#ifndef FALLOC_H
# error must include falloc
#endif
#ifndef CORE_H
# include "..\..\..\Core\System\Core.h"
#endif
#include "Limits.h"

namespace System { namespace Scheduler {

	class SliceFractionCache
	{
	private:
		fallocContext* _fallocCtx;
		SliceFractionCollection* _sliceFractions;
        ulong _fractions[EngineSettings__MaxWorkingFractions];
        int _currentFractionIndex;
        ulong _minFraction;
        ulong _maxFraction;
        ulong _currentFraction;

	public:
		bool RequiresRebuild;

		__device__ void xtor(fallocHeap* heap)
		{
			trace(SliceFractionCache, "xtor");
			_fallocCtx = fallocCreateCtx(heap);
		}
		__device__ void Dispose()
		{
			trace(SliceFractionCache, "Dispose");
			fallocDisposeCtx(_fallocCtx);
		}

		//__device__ SliceFraction MoveNextSliceFraction()
  //      {
  //          _minFraction = _currentFraction; //: fractions.Remove(fractionTime);
  //          _currentFraction = (_currentFractionIndex > 0 ? _fractions[--_currentFractionIndex] : ulong.MaxValue); //: repnz requires one less register
  //          return _sliceFractions[_minFraction];
  //      }

		__device__ void EnsureCache(ulong fraction)
        {
            if (fraction < _maxFraction)
                RequiresRebuild = true;
        }
	};

}}

#endif // SLICEFRACTIONCACHE_H
